<%@page import="util.TextFormat"%>
<%@page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Map"%>
<%@page import="entity.Category"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
	List<Map<String, Object>> categoryList = (List<Map<String, Object>>)request.getAttribute("categoryList");
	if(categoryList == null || categoryList.size() == 0){
		categoryList = new ArrayList<Map<String, Object>>();
	}
	Category parentCategory = (Category)request.getAttribute("parentCategory");
	Integer sub_id = (Integer)request.getAttribute("sub_id");
	Integer parent_id = (Integer)request.getAttribute("parent_id");
	String order = (String)request.getAttribute("order");
	List<Map<String, Object>> bookList = (List<Map<String, Object>>)request.getAttribute("bookList");
	if(bookList == null || bookList.size() == 0){
		bookList = new ArrayList<Map<String, Object>>();
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>当当图书 – 全球最大的中文网上书店</title>
		<link href="<%=request.getContextPath()%>/css/book.css" rel="stylesheet" type="text/css" />
		<link href="<%=request.getContextPath()%>/css/second.css" rel="stylesheet" type="text/css" />
		<link href="<%=request.getContextPath()%>/css/secBook_Show.css" rel="stylesheet" type="text/css" />
		<link href="<%=request.getContextPath()%>/css/list.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.3.js"></script>
		<script type="text/javascript">
			function orderBook(order){
				jQuery.noConflict();
				window.location.href = jQuery("a[name='selectedSub']").attr("href") + "&order=" + order;
			}
			
			function buyBook(id){
			<%
				if(session.getAttribute("user") == null){
			%>
					window.location.href = "<%=request.getContextPath()%>/user/logInOut/toLogin.do";
			<%
				} else {
			%>
					jQuery.noConflict();
					jQuery.ajax({
						type:"POST",
						url:"<%=request.getContextPath()%>/cart/buy.do",
						data:"id=" + id,
						beforeSend:function(){
							jQuery("#buy_"+id).attr("src","<%=request.getContextPath()%>/images/window_loading.gif");
						},
						success: function(msg){
							if(msg === 'true'){
								jQuery("#cartinfo_" + id).attr("style", "color:green;").html("购买成功");
								jQuery("#buy_" + id).attr("src","<%=request.getContextPath()%>/images/buttom_goumai.gif");
								setTimeout(function(){
									jQuery("#cartinfo_" + id).attr("style", "").html("");
								},2000);
							} else {
								jQuery("#cartinfo_" + id).attr("style", "color:red;").html("您已经购买");
								jQuery("#buy_"+id).attr("src","<%=request.getContextPath()%>/images/buttom_goumai.gif");
								setTimeout(function(){
									jQuery("#cartinfo_" + id).attr("style", "").html("");
								},2000);
							}
						}
					});
			<%
				}
			%>
			}
		</script>
	</head>
	<body id="body">
		&nbsp;

		<!-- 头部开始 -->
		<%@include file="../common/head.jsp"%>
		<!-- 头部结束 -->

		<div style="width: 962px; margin: auto;">
			<a href="#"><img src="<%=request.getContextPath()%>/images/default/book_banner_081203.jpg" border="0" /> </a>
		</div>
		<div class='your_position'>
			您现在的位置:&nbsp;
			<a href='<%=request.getContextPath()%>/main/toMain.do'>当当图书</a> &gt;&gt;
			<font style='color: #cc3300'><strong><%=parentCategory == null? "" : parentCategory.getName()%></strong> </font>
		</div>

		<div class="book">

			<!--左栏开始-->
			<div id="left" class="book_left">
				<div id="__fenleiliulan">
					<div class="second_l_border2">
						<h2>
							分类浏览
						</h2>
						<ul>
							<li>
								<div>
									<div class="second_fenlei">
										&middot;全部&nbsp;(${totalCount})
									</div>
								</div>
							</li>
							<li>
								<div class="clear"></div>
							</li>
							
							
							<!--2级分类开始-->
						<%
							for(int i = 0;i < categoryList.size(); i++){
								Map<String, Object> category = categoryList.get(i);
						%>
							<li>
								<div>
									<div class="second_fenlei">
										&middot;
									</div>
									<div class="second_fenlei">
									<%
										if(((Integer)category.get("id")).intValue() == sub_id.intValue()){
									%>
											<a href='<%=request.getContextPath()%>/main/bookList.do?parent_id=<%=parent_id%>&sub_id=<%=TextFormat.getText(category, "id")%>&page=1' 
													style="color:red; font-size:13px; font-weight: 900;" name="selectedSub">
												<%=TextFormat.getText(category, "name")%>&nbsp;(<%=TextFormat.getText(category, "count")%>)
											</a>
									<%
										} else {
									%>
											<a href='<%=request.getContextPath()%>/main/bookList.do?parent_id=<%=parent_id%>&sub_id=<%=TextFormat.getText(category, "id")%>&page=1'>
												<%=TextFormat.getText(category, "name")%>&nbsp;(<%=TextFormat.getText(category, "count")%>)
											</a>
									<%
										}
									%>
									</div>
								</div>
							</li>
							<li>
								<div class="clear"></div>
							</li>
						<%
							}
						%>
							<!--2级分类结束-->
							
							<li>
								<div></div>
							</li>
						</ul>
					</div>
				</div>
			</div>

			<!--左栏结束-->

			<!--中栏开始-->
			<div class="book_center">

				<!--图书列表开始-->
				<div id="divRight" class="list_right">

					<div id="book_list" class="list_r_title">
						<div class="list_r_title_text">
							排序方式
						</div>
						<select onchange='orderBook(this.value);' name='select_order' size='1'
							class='list_r_title_ml'>
							<option value="add_time" <%=order.equals("add_time") ? "selected='selected'" : ""%>>
								按上架时间 降序
							</option>
							<option value="dang_price" <%=order.equals("dang_price") ? "selected='selected'" : ""%>>
								按价格 升序
							</option>
						</select>
						<div id="divTopPageNavi" class="list_r_title_text3">

							<!--分页导航开始-->
							<c:choose>
								<c:when test="${page <= 1}">
									<div class='list_r_title_text3a'>
										<img src='<%=request.getContextPath()%>/images/page_up_gray.gif' />
									</div>
								</c:when>
								<c:otherwise>
									<div class='list_r_title_text3a'>
										<a name="link_page_next" href="<%=request.getContextPath()%>/main/bookList.do?parent_id=<%=parent_id%>&sub_id=<%=sub_id%>&page=${page - 1}">
											<img src='<%=request.getContextPath()%>/images/page_up.gif'/>
										</a>
									</div>
								</c:otherwise>
							</c:choose>
				
							<div class='list_r_title_text3b'>
								第${page}页/共${totalPageCount}页
							</div>
							
							<c:choose>
								<c:when test="${page >= totalPageCount}">
									<div class='list_r_title_text3a'>
										<img src='<%=request.getContextPath()%>/images/page_down_gray.gif'/>
									</div>
								</c:when>
								<c:otherwise>
									<div class='list_r_title_text3a'>
										<a name="link_page_next" href="<%=request.getContextPath()%>/main/bookList.do?parent_id=<%=parent_id%>&sub_id=<%=sub_id%>&page=${page + 1}">
											<img src='<%=request.getContextPath()%>/images/page_down.gif'/>
										</a>
									</div>
								</c:otherwise>
							</c:choose>
							<!--分页导航结束-->
						</div>
					</div>
					
					<!--商品条目开始-->
						
						<div class="list_r_line"></div>
						<div class="clear"></div>

					<%
						for(int i = 0; i < bookList.size(); i++){
							Map<String, Object> book = bookList.get(i);
					%>
						<div class="clear"></div>
						<div class="list_r_list">
							<span class="list_r_list_book">
								<a name="link_prd_img" href='#'><img src="<%=request.getContextPath()%>/productImages/<%=TextFormat.getText(book, "product_pic")%>"/></a>
							</span>
							<h2>
								<a name="link_prd_name" href='#'><%=TextFormat.getText(book, "product_name")%></a>
							</h2>
							<h3>
								顾客评分：100
							</h3>
							<h4 class="list_r_list_h4">
								作 者:
								<a href='#' name='作者'><%=TextFormat.getText(book, "author")%></a>
							</h4>
							<h4>
								出版社：
								<a href='#' name='出版社'><%=TextFormat.getText(book, "publishing")%></a>
							</h4>
							<h4>
								出版时间：<%=TextFormat.formatToYMD(book, "publish_time")%>
							</h4>
							<h5>
								<%=TextFormat.getText(book, "description")%>
							</h5>
							<div class="clear"></div>
							<h6>
								<span class="del">￥<%=TextFormat.formatNumber(book, "fixed_price")%></span>
								<span class="red">￥<%=TextFormat.formatNumber(book, "dang_price")%></span>
								节省：￥<%=TextFormat.formatNumber(book, "minus")%>
							</h6>
							<span class="list_r_list_button"></span>
							<a href="#"> 
								<img src='<%=request.getContextPath()%>/images/buttom_goumai.gif' id="buy_<%=TextFormat.getText(book, "id")%>" 
										onclick="buyBook(<%=TextFormat.getText(book, "id")%>)"/>
							</a>
							<span id="cartinfo_<%=TextFormat.getText(book, "id")%>"></span>
						</div>
						<div class="clear"></div>
					<%
						}
					%>
						<div class="clear"></div>
					
						<!--商品条目结束-->

					<div class="clear"></div>
					<div id="divBottomPageNavi" class="fanye_bottom">
					</div>

				</div>
				<!--图书列表结束-->

			</div>
			<!--中栏结束-->
			<div class="clear"></div>
		</div>

		<!--页尾开始 -->
		<%@include file="../common/foot.jsp"%>
		<!--页尾结束 -->
	</body>
</html>
